<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
use think\Db;

// 应用公共文件
function freeTimeShebei($resultData,$name){//设备空闲时间
    $setsArr=Db::query("select value from sets where id=3");
    $shebeiArr=explode('|',$setsArr[0]['value']);

    foreach ($shebeiArr as $keyS=>$valueS) {
        if(substr_count($valueS,$name)){

            $timeArr=explode('-',$valueS);
            $shebeiNum=$timeArr[1];


            $nodeArr=[];
            //dd($resultData);
            foreach($resultData as $key=>$value){
                $hourStr=date('H:i',strtotime($value['shijian']));
                $hourArr=explode(':',$hourStr);
                $hour=$hourArr[0];
                $spendtime=str_replace(array('小时','分钟'),'',$value['spendtime']);

                if($spendtime<10){
                    $min=$spendtime*60;
                }else{
                    $min=$spendtime;
                }

                $qd=$hourArr[0]*2+intval($hourArr[1]/30);
                $zd=$qd+intval($min/30);
                for($i=$qd;$i<$zd;$i++){
                    array_push($nodeArr,$i);
                }

            }


            $nodeCountArr=array_count_values($nodeArr);//重复次数
            $nodeArr=[];
            foreach($nodeCountArr as $key=>$value){
                if($value>=$shebeiNum){
                    array_push($nodeArr,$key);
                }
            }

            sort($nodeArr);


            return $nodeArr;break;
        }else{
        }
    }
    return 0;
}